package com.ruoyi.web.controller.edh;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.edh.domain.EdhIssue;
import com.ruoyi.edh.domain.vo.EdhIssueVo;
import com.ruoyi.edh.service.IEdhIssueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 易订货-学院发布内容Controller
 *
 * @author xxx
 * @date 2020-09-02
 */
@RestController
@RequestMapping("/edh/issue")
@Api(description = "易订货-学院发布内容相关")
public class EdhIssueController extends BaseController {
    @Autowired
    private IEdhIssueService edhIssueService;

    /**
     * app段学院内容列表接口
     */
    @GetMapping("/list")
    @ApiOperation("学院发布内容列表")
    public TableDataInfo list(EdhIssue edhIssue) {
        startPage();
        List<EdhIssueVo> list = edhIssueService.selectEdhIssueList(edhIssue);
        return getDataTable(list);
    }

    /**
     * pc端学院管理列表接口
     */
    @GetMapping("/pc/list")
    @ApiOperation("学院发布内容列表")
    public TableDataInfo pclist(EdhIssue edhIssue) {
        startPage();
        List<EdhIssueVo> list = edhIssueService.selectEdhIssuePcList(edhIssue);
        return getDataTable(list);
    }

    /**
     * 导出易订货-学院发布内容列表
     */
    @Log(title = "易订货-学院发布内容", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出学院发布内容列表")
    public AjaxResult export(EdhIssue edhIssue) {
        List<EdhIssueVo> list = edhIssueService.selectEdhIssueList(edhIssue);
        ExcelUtil<EdhIssueVo> util = new ExcelUtil<EdhIssueVo>(EdhIssueVo.class);
        return util.exportExcel(list, "issue");
    }

    /**
     * 获取易订货-学院发布内容详细信息
     */
    @GetMapping("/info")
    @ApiOperation("获取学院发布内容详细信息")
    public AjaxResult getInfo(Long id) {
        return AjaxResult.success(edhIssueService.selectEdhIssueById(id));
    }

    /**
     * 新增易订货-学院发布内容
     */
    @Log(title = "易订货-学院发布内容", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("学院发布内容")
    public AjaxResult add(@RequestBody EdhIssue edhIssue) {
        return toAjax(edhIssueService.insertEdhIssue(edhIssue));
    }

    /**
     * 修改易订货-学院发布内容
     */
    @Log(title = "易订货-学院发布内容", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改易学院发布内容")
    public AjaxResult edit(@RequestBody EdhIssue edhIssue) {
        return toAjax(edhIssueService.updateEdhIssue(edhIssue));
    }

    /**
     * 删除易订货-学院发布内容
     */
    @Log(title = "易订货-学院发布内容", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除学院发布内容")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(edhIssueService.deleteEdhIssueByIds(ids));
    }

    @GetMapping("/audit")
    @Log(title = "学院发布内容审核", businessType = BusinessType.UPDATE)
    @ApiOperation("学院发布内容审核")
    public AjaxResult audit(Long id, String status, String remake) {
        return toAjax(edhIssueService.audit(id, status, remake));
    }
}
